package com.example.criminalintent;

import java.util.Date;
import java.util.UUID;

import org.json.JSONException;
import org.json.JSONObject;

public class Crime {

	private static final String JSON_ID = "id";
	private static final String JSON_TITLE = "title";
	private static final String JSON_DATE = "date";
	private static final String JSON_SOLVED = "solved";
	
	private UUID 	mId;
	private String 	mTitle;
	private Date 	mDate;
	private boolean mSolved;  
	public Crime(){
		mId = UUID.randomUUID();
		mDate = new Date();
	}
	public Crime(JSONObject jobj) throws JSONException{
		mId = UUID.fromString(jobj.getString(JSON_ID));
		mTitle = jobj.getString(JSON_TITLE);
		mSolved = jobj.getBoolean(JSON_SOLVED);
		mDate = new Date(jobj.getLong(JSON_DATE));
	}
	public UUID getId() {
		return mId;
	}

	public Date getDate() {
		return mDate;
	}

	public void setDate(Date date) {
		mDate = date;
	}

	public boolean isSolved() {
		return mSolved;
	}

	public void setSolved(boolean solved) {
		mSolved = solved;
	}

	public String getTitle() {
		return mTitle;
	}
	public void setTitle(String title) {
		mTitle = title;
	}
	
	@Override
	public String toString(){
		return mTitle;
	}
	
	public JSONObject toJson(){
		JSONObject jobj = new JSONObject();
		try {
			jobj.put(JSON_ID, mId);
			jobj.put(JSON_TITLE, mTitle);
			jobj.put(JSON_DATE, mDate.getTime());
			jobj.put(JSON_SOLVED, mSolved);
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return jobj;
	}
}
